<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="角色1:">
        <el-select v-model="member1" placeholder="请选择" style="width: 200px">
         <el-option v-for="role in roles" :key="role" :value="role" />
        </el-select>
      </el-form-item>
      <el-form-item label="角色2:">
        <el-select v-model="member2" placeholder="请选择" style="width: 200px">
            <el-option v-for="role in roles" :key="role" :value="role" />
        </el-select>
      </el-form-item>
      <el-form-item label="关系:">
        <el-button type="primary" @click="computeResult"> 计算结果 </el-button>
        <el-input v-model="result" style="width: 100px; margin-left: 10px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="resetForm" style="width: 200px">
          重置
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  data() {
    return {
      member1: "",
      member2: "",
      result: "",
      roles: ["爸爸", "妈妈", "儿子", "女儿", "爷爷", "奶奶"]
    };
  },
  methods: {
    computeResult() {
      const relationship = {
        爸爸: {
          妈妈: "夫妻",
          儿子: "父子",
          女儿: "父女",
          爷爷: "父子",
          奶奶: "母子",
        },
        妈妈: {
          爸爸: "夫妻",
          儿子: "母子",
          女儿: "母女",
          爷爷: "父女",
          奶奶: "母女",
        },
        儿子: {
          爸爸: "父子",
          妈妈: "母子",
          爷爷: "祖父",
          奶奶: "祖母",
          女儿: "兄妹",
        },
        女儿: {
          爸爸: "父女",
          妈妈: "母女",
          爷爷: "祖父",
          奶奶: "祖母",
          儿子: "姐弟",
        },
        爷爷: {
          爸爸: "父子",
          妈妈: "父女",
          奶奶: "夫妻",
        },
        奶奶: {
          爸爸: "父子",
          妈妈: "母子",
          爷爷: "夫妻",
        },
      };
      this.result = relationship[this.member1]?.[this.member2] || "暂无关系";
    //   if (
    //     relationship[this.member1] &&
    //     relationship[this.member1][this.member2]
    //   ) {
    //     this.result = relationship[this.member1][this.member2];
    //   } else {
    //     this.result = "暂无关系";
    //   }
    },
    resetForm() {
      this.member1 = "";
      this.member2 = "";
      this.result = "";
    },
  },
};
</script>


<style scoped>
h1 {
  margin-bottom: 20px;
}
</style>